<?

//Data loading
$title='KAS - BON';
$title2='PEMBAYARAN UANG JALAN';
//if (GetParam("office","")) $perush = GetCompany (GetParam("office",""));
//else $perush = 'PT. MASAJI PRAYASA CARGO';

$jobslip_id = $_REQUEST['jobslip_id'];

$perush = 'PT. MASAJI PRAYASA CARGO';

$page   = 'PAGE';

$today = date("d/m/Y");   

$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = GridList ();
$pdf->GridTable($Result);
$pdf->Output();


function GridList () {
            global $jobslip_id,$DBGeneral;
            $DBConnection = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
                   
			$SQL = "SELECT * FROM tbljobslip_truck_detail as a
					JOIN tbljobslip_truck as b ON a.jobslip_id = b.jobslip_id
					JOIN tblactivity_setup as c ON a.activities_id = c.act_nr_id
					JOIN tbljoborder d ON b.jo_id = d.jo_id
					JOIN ".$DBGeneral.".tblstaff as e on b.paid_to_code = e.nik                            
					WHERE b.jobslip_id='".$jobslip_id."' ORDER BY jobslip_detail_id ASC ";
					
					
			return $DBConnection->dbc->get_results($SQL,ARRAY_A);
}

function ReadHeader($nobkt) {
  global $DBConnection;
  $SQL = "SELECT *,DATE_FORMAT(tglbkt,'%d %M, %Y') as spell_date  FROM ais_advance WHERE nobkt='$nobkt' LIMIT 1";
  return $DBConnection->dbc->get_row($SQL);
}


class PDFReport extends PDF {

    function Header() {
        
        global $title,$title2,$perush,$page,$DEFINE_FONT, $DBConnection,$jobslip_id,$DBGeneral,$today;
        
             
        
        if ($DEFINE_FONT==0) 
        {
            $this->AddFont('Arial','','arialn.php');
            $DEFINE_FONT=1;
        }
		

        $SQLHeader = "SELECT * FROM tbljobslip_truck as a 
					  JOIN tbljoborder as b ON a.jo_id = b.jo_id
					  JOIN ".$DBGeneral.".tblstaff as c on a.paid_to_code = c.nik  
					  JOIN tblproject as d ON b.project_id = d.project_id
					  JOIN tbldebtur as e ON b.debtur = e.CUDEBTUR
					  WHERE a.jobslip_id='".$jobslip_id."' ";
	
		$resultHeader = $DBConnection->dbc->get_results($SQLHeader,ARRAY_A);
        
		$this->SetFont('Arial','',10);
		$this->Cell(50,1,"",0,0,'L',0);
		$this->Ln();
		$this->SetLeftMargin(15);
		$this->Cell(50,1,"",0,0,'L',0);
		$this->Ln();
		$this->SetFont('Arial','',13);
		$this->Cell(50,5,$perush,0,0,'L',0);
		$this->SetFont('Arial','',10);
		$this->Cell(155,5,GetParam("nobkt",""),0,0,'R',0);
		$this->Ln();
		$this->SetFont('Arial','',13);
		$this->Cell(50,5,"JAKARTA",0,0,'L',0);
		$this->Ln();
		$this->SetFont('Arial','',16);
	   
		$this->Cell(205,7,$title2,0,1,'C',0);
		$this->SetFont('Arial','',10);
		$this->SetLeftMargin(15);
		$this->Ln();
                
                

       
		$SQLCurr = "SELECT DISTINCT curr as job_costing_curr FROM ais_advance a
					WHERE nobkt='".GetParam("nobkt","")."' ORDER BY urut";

		$Curr = $DBConnection->dbc->get_var($SQLCurr);


		$w=array(15,140,50);
		$this->SetFont('Arial','',11);
		$this->Cell(100,7,"JOB ORDER: ".$resultHeader[0]['jo_code'],0,0,'L',0);
		$this->Cell(100,7,"TANGGAL: ".$today,0,0,'L',0);
		$this->Ln();		
		$this->Cell(200,7,"JENIS ALAT : ".$resultHeader[0]['truck_mark'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"PROYEK: ".$resultHeader[0]['project_name']." / ".$resultHeader[0]['CUNAME'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"KAPAL: ".$resultHeader[0]['vessel'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"TRAYEK: ".$resultHeader[0]['trayek'],0,0,'L',0);
		$this->Ln();
		$this->Cell(100,7,"CARGO: MATERIAL PROYEK",0,0,'L',0);
		$this->Ln();
		$this->Ln();
		$this->Cell(100,7,"RINCIAN BIAYA",0,0,'L',0);
		$this->Ln();
		$this->Cell(25,7," ",'T',0,'L',0);
		$this->Ln();
            
    }

    function GridTable($MyResult) {
        
        global $DBConnection,$DBGeneral,$today, $jobslip_id;
        
        //echo "<pre>";
        //print_r($MyResult);
                
        $SQLHeader = "SELECT * FROM tbljobslip_truck as a 					
					  JOIN ".$DBGeneral.".tblstaff as c on a.paid_to_code = c.nik  
					  WHERE a.jobslip_id='".$jobslip_id."' ";
	
		$resultHeader = $DBConnection->dbc->get_results($SQLHeader,ARRAY_A);
		
		$driver = $resultHeader[0]['nama'];
		
		
        $grand_total+= 0;
        $w=array(15,140,50);
        //Data
        
        if ($MyResult)
        {         
			foreach($MyResult as $row)
			{
		   		
				$this->Cell(120,7,$row['actname'],0,0,'L',0);
				$this->Cell(10,7,"Rp. ",0,0,'L',0);
				$this->Cell(40,7,number_format($row['tax_amount'],2),0,0,'R',0);
				$this->Ln();
				
				$grand_total+= intval($row['tax_amount']);
				
			}
			
			$this->Cell(170,7," ",'B',0,'L',0);
			$this->Ln();
			
		 }
		 
		$this->Cell(120,7,"TOTAL",0,0,'L',0);
		$this->Cell(10,7,"Rp. ",0,0,'L',0);
		$this->Cell(40,7,number_format($grand_total,2),0,0,'R',0);
				
		$this->Ln();
		$this->Ln();
		$this->Ln();
		$this->Ln();
		

		$GetPerson = $DBConnection->dbc->get_row("SELECT * FROM tblprofile", ARRAY_A);
				
		//$this->Cell(50,5,$GetPerson["ttdbs1"],1,0,'C',0);
		
        $this->Cell(130,7,"",0,0,'L',0);
		$this->Cell(50,7,"Tanda Terima",0,0,'L',0);		
		$this->Ln();
		$this->Cell(130,7,"",0,0,'L',0);
		$this->Cell(50,7,"Tanjung Priok, ".$today,0,0,'L',0);		
		$this->Ln();
		$this->Cell(130,20,"",0,0,'L',0);
		$this->Cell(50,20,"",0,0,'L',0);		
		$this->Ln();
		$this->Cell(130,7,"",0,0,'L',0);
		$this->Cell(50,7,$driver,0,0,'L',0);		
		$this->Ln();


        //Closure line
    }

    function Footer() {
        //Closure line
        //$this->Cell(205,0,'','T');
    }

}


?>
